﻿namespace NMortgage.UI.Tests.Model
{
    using System;

    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using NMortgage.UI.Model;

    [TestClass]
    public class NormalDistributionTest
    {
        #region Properties

        private NormalDistribution Subject
        {
            get;
            set;
        }

        #endregion Properties

        #region Methods

        [TestMethod]
        public void Get_rate_with_high_stddev()
        {
            Subject.Mean = 6d;
            Subject.StdDev = Subject.Mean / 3d - 0.0001d;

            double min = 0d;
            double max = Subject.Mean + (Subject.StdDev * 7d);

            double actual;
            bool result;

            for (int i = 0; i < 1000000; i++)
            {
                actual = Subject.GetRate();
                result = IsBetween(actual, min, max);
                Assert.IsTrue(result);
            }
        }

        //[TestMethod]
        //public void GenerateDataFileTest()
        //{
        //    Subject.Mean = 5d;
        //    Subject.StdDev = 1d;
        //    double actual;
        //    using (System.IO.StreamWriter sw = System.IO.File.AppendText(@"C:\temp\norm100000.txt"))
        //    {
        //        for (int i = 0; i < 100000; i++)
        //        {
        //            actual = Subject.GetRate();
        //            sw.WriteLine(actual);
        //        }
        //    }
        //    Assert.IsTrue(true);
        //}
        //[TestMethod]
        //public void GenerateDataFileWithHighStdDevTest()
        //{
        //    Subject.Mean = 6d;
        //    Subject.StdDev = Subject.Mean/3d-0.0001d;
        //    double actual;
        //    using (System.IO.StreamWriter sw = System.IO.File.AppendText(@"C:\temp\norm-c-100000.txt"))
        //    {
        //        for (int i = 0; i < 100000; i++)
        //        {
        //            actual = Subject.GetRate();
        //            sw.WriteLine(actual);
        //        }
        //    }
        //    Assert.IsTrue(true);
        //}
        [TestMethod]
        public void Get_rate_with_mean5_dev_1()
        {
            Subject.Mean = 5d;
            Subject.StdDev = 1d;

            double min = 0d;
            double max = Subject.Mean + (Subject.StdDev * 10d);

            double actual;
            bool result;

            for (int i = 0; i < 1000000; i++)
            {
                actual = Subject.GetRate();
                result = IsBetween(actual, min, max);
                Assert.IsTrue(result);
            }
        }

        [TestInitialize]
        public void InitializeTest()
        {
            Subject = new NormalDistribution();
        }

        [TestMethod]
        public void MeanTest()
        {
            double expected = 5d;
            double actual;
            Subject.Mean = expected;
            actual = Subject.Mean;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Description
        ///</summary>
        [TestMethod]
        public void RateDescriptionTest()
        {
            string actual;
            actual = Subject.Description;
            Assert.IsNotNull(actual);
        }

        [TestMethod]
        public void StdDevTest()
        {
            double expected = 1d;
            double actual;
            Subject.StdDev = expected;
            actual = Subject.StdDev;
            Assert.AreEqual(expected, actual);
        }

        private bool IsBetween(double target, double min, double max)
        {
            return (target >= (min / 100d) && target <= (max / 100d));
        }

        #endregion Methods
    }
}